package com.aabte.design2.structural.composite;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
public class ImageEditor {

    private CompoundGraphic all;

    public static void main(String[] args) {
        ImageEditor imageEditor = new ImageEditor();
        imageEditor.load();

        List<Graphic> components = new LinkedList<>();
        components.add(new Dot(1, 2));
        components.add(new Circle(5, 3, 10));
        CompoundGraphic compoundGraphic = new CompoundGraphic();
        compoundGraphic.add(components.get(0));
        compoundGraphic.add(components.get(1));
        components.add(compoundGraphic);

        imageEditor.groupSelected(components);
    }

    private void load() {
        all = new CompoundGraphic();
        all.add(new Dot(1, 2));
        all.add(new Circle(5, 3, 10));
    }

    /**
     * 将所需组件组合为复杂的组合组件
     *
     * @param components
     */
    private void groupSelected(List<Graphic> components) {
        CompoundGraphic group = new CompoundGraphic();
        for (Graphic component : components) {
            group.add(component);
            all.remove(component);
        }
        all.add(group);
        all.draw(0);
    }

}
